var pageWd, pageHt;
		pageWd = $(window).width(),
		pageHt = $(window).height();
var os = detectOS();
//------------判断浏览器、操作系统
function detectOS() {
    var userAgent = navigator.userAgent;
    //console.log(userAgent);
    var os = {};
    os.android = userAgent.match(/(Android)\s+([\d.]+)/) || userAgent.match(/Silk-Accelerated/) ? true: false;
    os.androidICS = os.android && userAgent.match(/(Android)\s4/) ? true: false;
    os.ipad = userAgent.match(/(iPad).*OS\s([\d_]+)/) ? true: false;
    os.iphone = ! os.ipad && userAgent.match(/(iPhone\sOS)\s([\d_]+)/) ? true: false;
    os.ios = os.ipad || os.iphone;
    os.wp = userAgent.match(/Windows Phone/) || userAgent.match(/IEMobile/) ? true: false;
    os.supportsTouch = ((window.DocumentTouch && document instanceof window.DocumentTouch) || 'ontouchstart' in window);
    return os;
} //end func
if (os.android || os.iphone || os.wp){
    location.href = "mobile/mobile.html";
};
//var dct;
//if ((navigator.userAgent.indexOf('MSIE') >= 0)
//    && (navigator.userAgent.indexOf('Opera') < 0)){
//    $('.testdrive_area').addClass('ie').removeClass('testdrive_area');
//    var page_hg_ie = $('html').height();
//    $('.ie').css('bottom','50px');
//}

$(document).ready(function(){
    $(window).scroll(function(){
        var accd = $(window).scrollTop();
        if(accd < 550){
            $('.menu_area ul li').removeClass('active');
            $('.no1').addClass('active');
        }else if(accd > 550 && accd < 1200){
            $('.menu_area ul li').removeClass('active');
            $('.no2').addClass('active');
        }else if(accd > 1200 && accd < 1850){
            $('.menu_area ul li').removeClass('active');
            $('.no3').addClass('active');
        }else if(accd > 1850 && accd < 2530){
            $('.menu_area ul li').removeClass('active');
            $('.no7').addClass('active');
        }else if(accd > 2530 && accd < 3200){
            $('.menu_area ul li').removeClass('active');
            $('.no6').addClass('active');
        }else if(accd > 3200 && accd < 3400){
            $('.menu_area ul li').removeClass('active');
            $('.no4').addClass('active');
        }else if(accd > 3400){
            $('.menu_area ul li').removeClass('active');
            $('.no5').addClass('active');
        };
    });

    $('.pt2_con').click(function(){
        $('.config_left').addClass('on');
        $('.config_right img').attr('src','images/config_pt2.png');
        $('.pt2_con').hide();
        $('.pt1_con').show();
    });
    $('.pt1_con').click(function(){
        $('.config_left').removeClass('on');
        $('.config_right img').attr('src','images/config_pt1.png');
        $('.pt2_con').show();
        $('.pt1_con').hide();
    });
    function window_resizez() {
        pageWd = $(window).width();
        pageHt = $(window).height();
        //if ($(window).height() > $(window).width()) {
        //    $('#turnBox').css({
        //        width: $(window).width(),
        //        height: $(window).height()
        //    });
        //    $('#turnBox').show();
        //}else{
        //    $('#turnBox').hide();
        //};
    };
    window_resizez();
    //$(window).scroll(function(){
    //    var page_hg = $('html').height();
    //    var bottom_logo_hg = $('.logo_bottom').height();
    //    var scroll_bar_xy = page_hg - bottom_logo_hg - pageHt -50;
    //    var scroll_window = $(window).scrollTop();
    //    if(scroll_window >= scroll_bar_xy){
    //        $('.testdrive_area').css('position','absolute');
    //        $('.testdrive_area').css('bottom','50px');
    //    }else{
    //        $('.testdrive_area').css('position','fixed');
    //        $('.testdrive_area').css('bottom','0px');
    //    }
    //});
    $('.no1').click(function(){
        $('html,body').animate({
            scrollTop: "0px"
        },500);
    });
    $('.no2').click(function(){
        $('html,body').animate({
            scrollTop: "650px"
        },500);
    });
    $('.no3').click(function(){
        $('html,body').animate({
            scrollTop: "1250px"
        },500);
    });
    $('.no4').click(function(){
        $('html,body').animate({
            scrollTop: "3261px"
        },500);
    });
    $('.no5').click(function(){
        $('html,body').animate({
            scrollTop: "3791px"
        },500);
    });
    $('.no6').click(function(){
        $('html,body').animate({
            scrollTop: "2600px"
        },500);
    });
    $('.no7').click(function(){
        $('html,body').animate({
            scrollTop: "1950px"
        },500);
    });

    $('.logo_top').click(function(){
        window.open("http://www.skoda.com.cn");
        //window.open
    });
    $('.logo_bottom_r').click(function(){
        window.open("http://www.skoda.com.cn");
    });
    $('.logo_bottom_l').click(function(){
        window.open("http://www.svw-volkswagen.com/zh.html");
    });


    $(window).on('resize', window_resizez);


    //fancybox
    $('#video_area_l').fancybox();
    $('#video_area').click(function(){
        $.fancybox.open({
            href : '#video_bkbg',
            type : 'inline',
            padding : 0
        });
    });

    //第一个左右翻页
    $('.map_tc').iosSlider({
        scrollbar: true,
        snapToChildren: true,
        desktopClickDrag: true,
        navNextSelector: $('.map_tc .next'),
        navPrevSelector: $('.map_tc .prev'),
        scrollbarLocation: 'top',
        scrollbarMargin: '10px 10px 0 10px',
        scrollbarBorderRadius: '0',
        responsiveSlideWidth: true,
        navSlideSelector: $('.map_tc .iosSliderButtons .button'),
        infiniteSlider: true,
        startAtSlide: '1',
        onSlideChange: slideContentChange,
        onSlideComplete: slideContentComplete,
        onSliderLoaded: slideContentLoaded
    });

    function slideContentChange(args) {

        /* indicator */
        $(args.sliderObject).parent().find('.iosSliderButtons .button').removeClass('selected');
        $(args.sliderObject).parent().find('.iosSliderButtons .button:eq(' + (args.currentSlideNumber - 1) + ')').addClass('selected');

    }

    function slideContentComplete(args) {


    }

    function slideContentLoaded(args) {

        /* indicator */
        $(args.sliderObject).parent().find('.iosSliderButtons .button').removeClass('selected');
        $(args.sliderObject).parent().find('.iosSliderButtons .button:eq(' + (args.currentSlideNumber - 1) + ')').addClass('selected');

    }

    function sd_slider(){
        //第二个左右翻页
        $('.jpg_area').iosSlider({
            scrollbar: true,
            snapToChildren: true,
            desktopClickDrag: true,
            navNextSelector: $('.vijp_area .vijp_right'),
            navPrevSelector: $('.vijp_area .vijp_left'),
            scrollbarLocation: 'top',
            scrollbarMargin: '10px 10px 0 10px',
            scrollbarBorderRadius: '0',
            responsiveSlideWidth: true,
            navSlideSelector: $('.jpg_area .iosSliderButtons .button'),
            infiniteSlider: true,
            startAtSlide: '1',
            onSlideChange: slideContentChange,
            onSlideComplete: slideContentComplete,
            onSliderLoaded: slideContentLoaded
        });

        function slideContentChange(args) {

            /* indicator */
            $(args.sliderObject).parent().find('.iosSliderButtons .button').removeClass('selected');
            $(args.sliderObject).parent().find('.iosSliderButtons .button:eq(' + (args.currentSlideNumber - 1) + ')').addClass('selected');

        }

        function slideContentComplete(args) {


        }

        function slideContentLoaded(args) {

            /* indicator */
            $(args.sliderObject).parent().find('.iosSliderButtons .button').removeClass('selected');
            $(args.sliderObject).parent().find('.iosSliderButtons .button:eq(' + (args.currentSlideNumber - 1) + ')').addClass('selected');

        }
    };



    $('.jpg_opbut').click(function(){
        $('.jpg_opbut').hide();
        $('.video_area').hide();
        $('.video_opbut').show();
        $('.vijp_left').show();
        $('.vijp_right').show();
        $('.jpg_area').show();
        $('.vijp_change_but').addClass('on');
        sd_slider();
    });
    $('.video_opbut').click(function(){
        $('.video_opbut').hide();
        $('.vijp_left').hide();
        $('.vijp_right').hide();
        $('.jpg_area').hide();
        $('.jpg_opbut').show();
        $('.video_area').show();
        $('.vijp_change_but').removeClass('on');
    });


    //第三个左右翻页
    $('.stk_area_main').iosSlider({
        scrollbar: true,
        snapToChildren: true,
        desktopClickDrag: true,
        navNextSelector: $('.stk_area .stk_right'),
        navPrevSelector: $('.stk_area .stk_left'),
        scrollbarLocation: 'top',
        scrollbarMargin: '10px 10px 0 10px',
        scrollbarBorderRadius: '0',
        responsiveSlideWidth: true,
        navSlideSelector: $('.stk_area .iosSliderButtons .button'),
        infiniteSlider: true,
        startAtSlide: '1',
        onSlideChange: slideContentChange,
        onSlideComplete: slideContentComplete,
        onSliderLoaded: slideContentLoaded
    });

    function slideContentChange(args) {

        /* indicator */
        $(args.sliderObject).parent().parent().find('.iosSliderButtons .button').removeClass('selected');
        $(args.sliderObject).parent().parent().find('.iosSliderButtons .button:eq(' + (args.currentSlideNumber - 1) + ')').addClass('selected');

    }

    function slideContentComplete(args) {


    }

    function slideContentLoaded(args) {

        /* indicator */
        $(args.sliderObject).parent().parent().find('.iosSliderButtons .button').removeClass('selected');
        $(args.sliderObject).parent().parent().find('.iosSliderButtons .button:eq(' + (args.currentSlideNumber - 1) + ')').addClass('selected');

    }
});